package com.java.system.controller;

import com.java.system.entity.Camera;
import com.java.system.entity.Result;
import com.java.system.service.ICameraService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  摄像头控制器
 * </p>
 *
 * @author xiaoman
 * @since 2023-07-12
 */
@RestController
@RequestMapping("/camera")
public class CameraController {
    @Autowired
    ICameraService cameraService;
    @GetMapping("/list")
    public Result getCamera(){
        List<Camera> cameraList = cameraService.select();
        int size = cameraList.size();
        if(!StringUtils.isEmpty(cameraList)){
            Result result=Result.success("获取全部摄像头成功");
            result.put("data",cameraList);
            result.put("size",size);
            return result;
        }
        else {
            return Result.error("获取信息失败");
        }
    }
    @PostMapping("/add")
    public Result insertCamera(@RequestBody Camera camera){
        cameraService.insert(camera);
        return Result.success("新增摄像头成功");
    }
    @GetMapping("/{id}")
    public Result getCameraById(@PathVariable("id")Integer id){
        Camera camera = cameraService.getCameraById(id);
        if(camera!=null){
            Result result=Result.success("根据ID查询摄像头成功");
            result.put("data",camera);
            return result;
        }
        else {
            return Result.error("获取信息失败");
        }

    }
    @PutMapping
    public Result updateCamera(@RequestBody Camera camera){
        cameraService.updateCamera(camera);
        return Result.success("修改摄像头信息成功");
    }
    @DeleteMapping("/{id}")
    public Result deleteCamera(@PathVariable("id")Integer id){
        cameraService.deleteCamera(id);
        return Result.success("删除摄像头成功");
    }
    @GetMapping("/access")
    public Result getAccess(){
        Integer count = cameraService.getAccessCount();
        Result result = Result.success("接入路线总数");
        result.put("data",count);
        return result;
    }
    @GetMapping("/ai")
    public Result getAi(){
        Integer count = cameraService.getAiCount();
        Result result = Result.success("AI测试点总数");
        result.put("data",count);
        return result;
    }

}
